package de.unihannover.hci.portraitquiz.helper;

import java.io.IOException;
import java.io.InputStream;

import de.unihannover.hci.portraitquiz.helper.ShapeObstacle.DIFFICULTY;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class ObstacleImageView extends ImageView {
	
	private Drawable currentObstacle;
	private int currentAlpha;
	private LayerDrawable currentDrawable;
	private Drawable image;
	private int layersSize;
	
	public ObstacleImageView(Context context) {
		super(context);
		currentObstacle = null;
		currentAlpha = 255;
		currentDrawable = null;
		// TODO Auto-generated constructor stub
	}
	
	public ObstacleImageView(Context context, AttributeSet as){
		super(context, as);
		currentAlpha = 255;
	}
	
	
	public void decreaseObstacleAlpha(int amount){
		Drawable [] layers;
		if(currentObstacle != null){
			layers = new Drawable[2];
			layers[1] = currentObstacle;
			currentAlpha -= amount;
			if(currentAlpha < 0){
				currentAlpha = 0;
			}
			currentObstacle.setAlpha(currentAlpha);
			
		}
		else layers = new Drawable[1];
		layers[0] = image;
		currentDrawable = new LayerDrawable(layers);
		super.setImageDrawable(currentDrawable);
	}
	
	public void setImage(Drawable image) {
		this.image = image;
		Drawable [] layers;			
		if(currentObstacle != null){
			layers = new Drawable[2];			
			layers[1] = currentObstacle;
		}
		else layers = new Drawable[1]; 
		layers[0] = image;
		currentAlpha = 255;
		currentDrawable = new LayerDrawable(layers);
		super.setImageDrawable(currentDrawable);
	}

	public void setObstacle(Drawable obstacle) {
		this.currentObstacle = obstacle;
		currentAlpha = 255;
	}

}
